<template>
    <div class="app-container">
        <!-- 输⼊表单 -->
        <el-form label-width="120px">
            <el-form-item label="借款额度">
                <el-input-number v-model="integralGrade.borrowAmount" :min="0" />
            </el-form-item>
            <el-form-item label="积分区间开始">
                <el-input-number v-model="integralGrade.integralStart" :min="0" />
            </el-form-item>
            <el-form-item label="积分区间结束">
                <el-input-number v-model="integralGrade.integralEnd" :min="0" />
            </el-form-item>
            <el-form-item>
                <el-button :disabled="saveBtnDisabled" type="primary" @click="saveOrUpdate()">
                    保存
                </el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
    import integralGradeApi from '@/api/core/integral-grade'
    export default {
    data() {
        return {
            id:"",
            integralGrade: {}, // 初始化数据
            saveBtnDisabled: false // 保存按钮是否禁⽤，防⽌表单重复提交
        }
    },
    created(){
        this.id=this.$route.params.id
        
        if(this.$route.params.id){this.getById(this.id)}
        
    },
    methods:{
        getById(id){
            integralGradeApi.getById(id).then(resp=>{
                this.integralGrade=resp.data.integralGrade;
            })
        },
        saveOrUpdate(){
            this.saveBtnDisabled=true
            let url = "/admin/core/integralGrade/add"
            let method="post"
            if (this.id) {
                url = "/admin/core/integralGrade/update"
                method="put" 
            }
            integralGradeApi.save(url,method,this.integralGrade).then(resp=>{
                this.$message.success(resp.message)
                this.$router.push("/core/integral-grade/list")
            })
            
        }
    }
}
</script>